// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "D3D10ShaderReflection.h"
#include "D3D10ShaderReflectionConstantBuffer.h"

using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D10;
using namespace msclr::interop;

ShaderReflectionConstantBuffer^ ShaderReflection::GetConstantBufferByIndex(UInt32 index)
{
    ID3D10ShaderReflectionConstantBuffer* returnValue = GetInterface<ID3D10ShaderReflection>()->GetConstantBufferByIndex(static_cast<UINT>(index));
    return returnValue == NULL ? nullptr : gcnew ShaderReflectionConstantBuffer(returnValue);
}

ShaderReflectionConstantBuffer^ ShaderReflection::GetConstantBufferByName(String^ name)
{
    marshal_context^ context = gcnew marshal_context();
    ID3D10ShaderReflectionConstantBuffer* returnValue = GetInterface<ID3D10ShaderReflection>()->GetConstantBufferByName(context->marshal_as<const char*>(name));
    return gcnew ShaderReflectionConstantBuffer(returnValue);
}

ShaderDescription^ ShaderReflection::GetDescription()
{
    ShaderDescription^ desc = gcnew ShaderDescription();    
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection>()->GetDesc(desc->nativeObject.Get()));    
    return desc;
}

SignatureParameterDescription^  ShaderReflection::GetInputParameterDescription(UInt32 parameterIndex)
{
    SignatureParameterDescription^  desc = gcnew SignatureParameterDescription();
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection>()->GetInputParameterDesc(static_cast<UINT>(parameterIndex), desc->nativeObject.Get()));
    return desc;
}

SignatureParameterDescription^ ShaderReflection::GetOutputParameterDescription(UInt32 parameterIndex)
{
    SignatureParameterDescription^ desc = gcnew SignatureParameterDescription();
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection>()->GetOutputParameterDesc(static_cast<UINT>(parameterIndex), desc->nativeObject.Get()));
    return desc;
}

ShaderInputBindDescription^ ShaderReflection::GetResourceBindingDescription(UInt32 resourceIndex)
{
    ShaderInputBindDescription^ desc = gcnew ShaderInputBindDescription();
    CommonUtils::VerifyResult(GetInterface<ID3D10ShaderReflection>()->GetResourceBindingDesc(static_cast<UINT>(resourceIndex), desc->nativeObject.Get()));
    return desc;
}

